/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.senaclem.persistencia;

import co.edu.senaclem.modelo.Comite;
import co.edu.senaclem.modelo.ComitePK;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author DILOVE
 */
@Stateless
public class ComiteDAO implements IComiteDAO {
    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    public void registrar(Comite comite) throws Exception {
        try {
            entityManager.persist(comite);
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public List<Comite> consultar(Integer numeroSeguimiento) throws Exception {
        try {
            String jpql="Select c From Comite c";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public void retirar(Comite comite) throws Exception {
        try {
            entityManager.remove(comite);
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public Comite consultarPorNumero(Integer numeroSeguimiento, Long documentoPersonal) throws Exception {
        try {
            ComitePK comitepk = new ComitePK(documentoPersonal, numeroSeguimiento);
            return entityManager.find(Comite.class, comitepk);
        } catch (RuntimeException e) {
            throw e;
        }
        
    }

    @Override
    public void modificar(Comite comite) throws Exception {        
        try {
            entityManager.merge(comite);
        } catch (RuntimeException e) {
            throw e;
        }
    }

}
